/*
 * @Author: wwssaabb
 * @Date: 2021-06-25 12:01:05
 * @LastEditTime: 2021-06-25 17:13:39
 * @FilePath: \demo\todo_list\src\store\index.ts
 */
import { ActionTree, CommitOptions, createLogger, createStore, DispatchOptions, Getter, Store as VuexStore } from 'vuex'
import { State , state} from './state'
import { Mutations, mutations } from './mutations'
import { Actions, actions } from './actions'
import { Getters, getters } from './getters'

export const store=createStore<State>({
  plugins:process.env.Node_ENV==='development'?[createLogger()]:[],
  state,
  mutations,
  actions,
  getters
})

export function useStore(){
  return store as Store 
}

export type Store =Omit<
  VuexStore<State>,
  'getters'|'commit'|'dispatch'>&{
    commit<k extends keyof Mutations,p extends Parameters<Mutations[k]>[1]>(
      key:k,
      payload:p,
      options:CommitOptions
    ):ReturnType<Mutations[k]>}&{
      dispatch<k extends keyof Actions>(
        key:k,
        payload:Parameters<Actions[k]>[1],
        options?:DispatchOptions
      ):ReturnType<Actions[k]>
    }&{
      getters:{
        [k in keyof Getters]:ReturnType<Getters[k]>
      }
    }